// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.Snapshot;

internal sealed partial class SourceOnlyRepositorySettingsConverter : JsonConverter<SourceOnlyRepositorySettings>
{
	public override SourceOnlyRepositorySettings Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
	{
		if (reader.TokenType != JsonTokenType.StartObject)
			throw new JsonException("Unexpected JSON detected.");
		var variant = new SourceOnlyRepositorySettings();
		while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
		{
			if (reader.TokenType == JsonTokenType.PropertyName)
			{
				var property = reader.GetString();
				if (property == "chunk_size")
				{
					variant.ChunkSize = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.ByteSize?>(ref reader, options);
					continue;
				}

				if (property == "compress")
				{
					variant.Compress = JsonSerializer.Deserialize<bool?>(ref reader, options);
					continue;
				}

				if (property == "delegate_type")
				{
					variant.DelegateType = JsonSerializer.Deserialize<string?>(ref reader, options);
					continue;
				}

				if (property == "max_number_of_snapshots")
				{
					variant.MaxNumberOfSnapshots = JsonSerializer.Deserialize<int?>(ref reader, options);
					continue;
				}

				if (property == "max_restore_bytes_per_sec")
				{
					variant.MaxRestoreBytesPerSec = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.ByteSize?>(ref reader, options);
					continue;
				}

				if (property == "max_snapshot_bytes_per_sec")
				{
					variant.MaxSnapshotBytesPerSec = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Serverless.ByteSize?>(ref reader, options);
					continue;
				}

				if (property == "read_only" || property == "readonly")
				{
					variant.ReadOnly = JsonSerializer.Deserialize<bool?>(ref reader, options);
					continue;
				}
			}
		}

		return variant;
	}

	public override void Write(Utf8JsonWriter writer, SourceOnlyRepositorySettings value, JsonSerializerOptions options)
	{
		writer.WriteStartObject();
		if (value.ChunkSize is not null)
		{
			writer.WritePropertyName("chunk_size");
			JsonSerializer.Serialize(writer, value.ChunkSize, options);
		}

		if (value.Compress.HasValue)
		{
			writer.WritePropertyName("compress");
			writer.WriteBooleanValue(value.Compress.Value);
		}

		if (!string.IsNullOrEmpty(value.DelegateType))
		{
			writer.WritePropertyName("delegate_type");
			writer.WriteStringValue(value.DelegateType);
		}

		if (value.MaxNumberOfSnapshots.HasValue)
		{
			writer.WritePropertyName("max_number_of_snapshots");
			writer.WriteNumberValue(value.MaxNumberOfSnapshots.Value);
		}

		if (value.MaxRestoreBytesPerSec is not null)
		{
			writer.WritePropertyName("max_restore_bytes_per_sec");
			JsonSerializer.Serialize(writer, value.MaxRestoreBytesPerSec, options);
		}

		if (value.MaxSnapshotBytesPerSec is not null)
		{
			writer.WritePropertyName("max_snapshot_bytes_per_sec");
			JsonSerializer.Serialize(writer, value.MaxSnapshotBytesPerSec, options);
		}

		if (value.ReadOnly.HasValue)
		{
			writer.WritePropertyName("read_only");
			writer.WriteBooleanValue(value.ReadOnly.Value);
		}

		writer.WriteEndObject();
	}
}

[JsonConverter(typeof(SourceOnlyRepositorySettingsConverter))]
public sealed partial class SourceOnlyRepositorySettings
{
	public Elastic.Clients.Elasticsearch.Serverless.ByteSize? ChunkSize { get; set; }
	public bool? Compress { get; set; }
	public string? DelegateType { get; set; }
	public int? MaxNumberOfSnapshots { get; set; }
	public Elastic.Clients.Elasticsearch.Serverless.ByteSize? MaxRestoreBytesPerSec { get; set; }
	public Elastic.Clients.Elasticsearch.Serverless.ByteSize? MaxSnapshotBytesPerSec { get; set; }
	public bool? ReadOnly { get; set; }
}

public sealed partial class SourceOnlyRepositorySettingsDescriptor : SerializableDescriptor<SourceOnlyRepositorySettingsDescriptor>
{
	internal SourceOnlyRepositorySettingsDescriptor(Action<SourceOnlyRepositorySettingsDescriptor> configure) => configure.Invoke(this);

	public SourceOnlyRepositorySettingsDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.ByteSize? ChunkSizeValue { get; set; }
	private bool? CompressValue { get; set; }
	private string? DelegateTypeValue { get; set; }
	private int? MaxNumberOfSnapshotsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.ByteSize? MaxRestoreBytesPerSecValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.ByteSize? MaxSnapshotBytesPerSecValue { get; set; }
	private bool? ReadOnlyValue { get; set; }

	public SourceOnlyRepositorySettingsDescriptor ChunkSize(Elastic.Clients.Elasticsearch.Serverless.ByteSize? chunkSize)
	{
		ChunkSizeValue = chunkSize;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor Compress(bool? compress = true)
	{
		CompressValue = compress;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor DelegateType(string? delegateType)
	{
		DelegateTypeValue = delegateType;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor MaxNumberOfSnapshots(int? maxNumberOfSnapshots)
	{
		MaxNumberOfSnapshotsValue = maxNumberOfSnapshots;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor MaxRestoreBytesPerSec(Elastic.Clients.Elasticsearch.Serverless.ByteSize? maxRestoreBytesPerSec)
	{
		MaxRestoreBytesPerSecValue = maxRestoreBytesPerSec;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor MaxSnapshotBytesPerSec(Elastic.Clients.Elasticsearch.Serverless.ByteSize? maxSnapshotBytesPerSec)
	{
		MaxSnapshotBytesPerSecValue = maxSnapshotBytesPerSec;
		return Self;
	}

	public SourceOnlyRepositorySettingsDescriptor ReadOnly(bool? readOnly = true)
	{
		ReadOnlyValue = readOnly;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (ChunkSizeValue is not null)
		{
			writer.WritePropertyName("chunk_size");
			JsonSerializer.Serialize(writer, ChunkSizeValue, options);
		}

		if (CompressValue.HasValue)
		{
			writer.WritePropertyName("compress");
			writer.WriteBooleanValue(CompressValue.Value);
		}

		if (!string.IsNullOrEmpty(DelegateTypeValue))
		{
			writer.WritePropertyName("delegate_type");
			writer.WriteStringValue(DelegateTypeValue);
		}

		if (MaxNumberOfSnapshotsValue.HasValue)
		{
			writer.WritePropertyName("max_number_of_snapshots");
			writer.WriteNumberValue(MaxNumberOfSnapshotsValue.Value);
		}

		if (MaxRestoreBytesPerSecValue is not null)
		{
			writer.WritePropertyName("max_restore_bytes_per_sec");
			JsonSerializer.Serialize(writer, MaxRestoreBytesPerSecValue, options);
		}

		if (MaxSnapshotBytesPerSecValue is not null)
		{
			writer.WritePropertyName("max_snapshot_bytes_per_sec");
			JsonSerializer.Serialize(writer, MaxSnapshotBytesPerSecValue, options);
		}

		if (ReadOnlyValue.HasValue)
		{
			writer.WritePropertyName("read_only");
			writer.WriteBooleanValue(ReadOnlyValue.Value);
		}

		writer.WriteEndObject();
	}
}